<?php
require_once("bizlayer/result_mgmt.php");

$resultRows = null;

if(!(isset($event) && $event > 0)){
	require_once("bizlayer/event_mgmt.php");
	$event = EventMgmt::getLatestEvent();
}
if(isset($event))
	$resultRows = ResultMgmt::getResultByYear($event->eventId);

?>
<div align="center">
	<?
	if(isset($event))
		printf("<h3>Final result of %s</h3>",$event->year);
	else
		echo "<br/><br/>";
	?>
</div>
<table border="1" width="100%" class="resultgrid">
	<tr>
		<td>&nbsp;</td>
		<td colspan="5" align="center">Castle Creek</td>
		<td colspan="5" align="center">Stone Bridge</td>
		<td colspan="5" align="center">Mill Pond</td>
		<td colspan="5" align="center">Hago's</td>
		<td colspan="3" align="center">Total</td>
	</tr>
	<tr>
		<td>Player</td>
		<td>Out</td>
		<td>In</td>
		<td>Total</td>
		<td>Par</td>
		<td>1's</td>
		<td>Out</td>
		<td>In</td>
		<td>Total</td>
		<td>Par</td>
		<td>1's</td>
		<td>Out</td>
		<td>In</td>
		<td>Total</td>
		<td>Par</td>
		<td>1's</td>
		<td>Out</td>
		<td>In</td>
		<td>Total</td>
		<td>Par</td>
		<td>1's</td>
		<td>Sum</td>
		<td>Par</td>
		<td>1's</td>
	</tr>
	<?if(count($resultRows) > 0){
		foreach ($resultRows as $row){?>
		<tr>
			<?
				printf("<td><a href=\"profile.php?playerid=%d\">%s</a></td>",$row["playerid"],$row["player"]);
				printf("<td>%s</td>",$row["castlecreek_out"]);
				printf("<td>%s</td>",$row["castlecreek_in"]);
				printf("<td>%s</td>",$row["castlecreek_total"]);
				printf("<td>%s</td>",$row["castlecreek_par"]);
				printf("<td>%s</td>",$row["castlecreek_holein1"]);
				printf("<td>%s</td>",$row["stonebridge_out"]);
				printf("<td>%s</td>",$row["stonebridge_in"]);
				printf("<td>%s</td>",$row["stonebridge_total"]);
				printf("<td>%s</td>",$row["stonebridge_par"]);
				printf("<td>%s</td>",$row["stonebridge_holein1"]);
				printf("<td>%s</td>",$row["millpond_out"]);
				printf("<td>%s</td>",$row["millpond_in"]);
				printf("<td>%s</td>",$row["millpond_total"]);
				printf("<td>%s</td>",$row["millpond_par"]);
				printf("<td>%s</td>",$row["millpond_holein1"]);
				printf("<td>%s</td>",$row["hagos_out"]);
				printf("<td>%s</td>",$row["hagos_in"]);
				printf("<td>%s</td>",$row["hagos_total"]);
				printf("<td>%s</td>",$row["hagos_par"]);
				printf("<td>%s</td>",$row["hagos_holein1"]);
				printf("<td>%s</td>",$row["grand_total"]);
				printf("<td>%s</td>",$row["grand_par"]);
				printf("<td>%s</td>",$row["grand_holein1"]);
			?>
		</tr>
	<?}
	}
	else{?>
		<tr>
			<td colspan="24" align="center">
				No result found.
			</td>
		</tr>
	<?}?>
</table>
